package orbito.graphics;

import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;

public class Viewport {

	// The halfwidth and halfheight of the rendered area.
	double halfw, halfh;

	public Viewport() {
		this(400, 300);
	}
	
	public Viewport(double width, double height) {
		this.halfw = width / 2;
		this.halfh = height / 2;
	}

	public AffineTransform getTransform() {
		AffineTransform tr = new AffineTransform();
		tr.translate(halfw, halfh);
		return tr;
	}

	public void transformGraphics(Graphics2D g) {
		g.translate(halfw, halfh);
	}

	public void setSize(double width, double height) {
		halfw = width / 2;
		halfh = height / 2;
	}

	public double getWidth() {
		return halfw * 2;
	}

	public double getHeight() {
		return halfh * 2;
	}
}
